package com.app.newiptv.helper;


import android.text.TextUtils;
import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.app.newiptv.bean.ChannelType;
import com.app.newiptv.bean.RequestDto;
import com.app.newiptv.bean.VodItemBean;
import com.app.newiptv.bean.VodListBean;
import com.app.newiptv.bean.allchannels.Program;
import com.app.newiptv.callback.IRequestCallback;
import com.app.newiptv.callback.IRequestLisenter;
import com.app.newiptv.utils.OkGoUtil;
import com.lzy.okhttputils.callback.StringCallback;

import java.util.List;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by wendal on 2017/9/16.
 */
public class VodItemHelper {

    private IRequestCallback callback;

    public VodItemHelper() {
    }

    public void setCallback(IRequestCallback callback) {
        this.callback = callback;
    }

    public void loadData(String url) {
        OkGoUtil<VodListBean> okGoUtil = new OkGoUtil<VodListBean>(null, OkGoUtil.TYPE_DATA, null);
        okGoUtil.requestNewPost(url, new StringCallback() {
            @Override
            public void onSuccess(String result, Call call, Response response) {
                Log.d("tag", "----------" + result);
                if (!TextUtils.isEmpty(result)) {
                    try {
                        VodItemBean vodItemBean = JSON.parseObject(result, VodItemBean.class);
                        VodItemBean.VodDataBean vodDataBean = vodItemBean.getData();
                        if (null != callback) {
                            callback.onLoadComplete("", 0, 0, vodDataBean);
                        }
                    }catch (Exception e) {
                        e.printStackTrace();
                    }

                } else {
                    if (null != callback) {
                        callback.onFailed(10001 + "", "result == null");
                    }
                }
            }

            @Override
            public void onError(Call call, Response response, Exception e) {
                super.onError(call, response, e);
                if (null != callback) {
                    callback.onFailed(response.code() + "", response.message());
                }
            }
        });
    }

}
